package com.sunrise.generico.entidade;

import java.util.Collection;
import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import lombok.Getter;
import lombok.Setter;

import org.hibernate.validator.constraints.NotEmpty;

import com.sunrise.generico.entidade.iface.EntidadeManter;
import com.sunrise.generico.enums.TipoCarteiraCobranca;
import com.sunrise.generico.enums.TipoContaCedente;

@Entity
@Table(name = "conta_cedente")
public class ContaCedente implements EntidadeManter {

	private static final long serialVersionUID = -3070159621011097321L;

	@Id
	@SequenceGenerator(name="pk_sequence",sequenceName="conta_cedente_id_seq", allocationSize=1)
	@GeneratedValue(strategy=GenerationType.SEQUENCE,generator="pk_sequence")
	@Column
	@Getter @Setter
	private Long id;
	
	@NotEmpty( message="{nomeObrigatorio}")
	@Column(name = "nome", length = 60, nullable = false)
	@Getter @Setter
	private String nome;
	
	@NotEmpty( message="{codigoBancoObrigatorio}")
	@Column(name = "codigoBanco", length = 3, nullable = false)
	@Getter @Setter
	private String codigoBanco;
	
	@NotNull( message="{carteiraObrigatorio}")
	@Column(name = "carteira", length = 10)
	@Getter @Setter
	private Integer carteira;
	
	@NotNull( message="{agenciaObrigatorio}")
	@Column(name = "agencia", length = 10)
	@Getter @Setter
	private Integer agencia;
	
	@NotNull( message="{contaCorrenteObrigatorio}")
	@Column(name = "contaCorrente", length = 10)
	@Getter @Setter
	private Long contaCorrente;
	
	@NotNull( message="{dvContaCorrenteObrigatorio}")
	@Column(name = "dvContaCorrente", length = 1)
	@Getter @Setter
	private char dvContaCorrente;
	
	@Column(name = "nossoNumero", length = 25)
	@Getter @Setter
	private Long nossoNumero;
	
	@Column(name = "numeroConvenio", length = 10)
	@Getter @Setter
	private String numeroConvenio;
	
	@Column(name = "variacaoCarteira", length = 10)
	@Getter @Setter
	private String variacaoCarteira;
	
	@Column(name = "modalidade", length = 10)
	@Getter @Setter
	private String modalidade;
	
	@Column(name = "codigoCliente", length = 10)
	@Getter @Setter
	private String codigoCliente;
	
	@Column(name = "codigoCedente", length = 10)
	@Getter @Setter
	private String codigoCedente;
	
	@Column(name = "dataAbertura")
	@Getter @Setter
	private Date dataAbertura;
	
	@OneToOne
	@Getter @Setter
	private Endereco endereco;
	
	@Enumerated
	@Getter @Setter
	private TipoContaCedente tipoConta;
	
	@Enumerated
	@Getter @Setter
	private TipoCarteiraCobranca tipoCarteira;
	
	@ManyToMany(fetch=FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE })
	@JoinTable(name="contaCedente_usuario", joinColumns={@JoinColumn(name="contaCedente_id", referencedColumnName="id")},
		      inverseJoinColumns={@JoinColumn(name="usuario_id", referencedColumnName="id")})
	@Getter @Setter
	private Collection<Usuario> usuarios;
	
	@Column(name = "ativo")
	@Getter @Setter
	private Boolean ativo;

}
